/**
 * Class: DRange
 *
 * Purpose: A range limiter (within min-max, inclusive)
 *
 * Created: Feb 22, 2010 @ 9:12:03 PM
 * @author Ken
 */
package org.openfantasia.util.math;

public class DRange {

	protected Double min;

	protected Double max;


	protected DRange() {
	}


	public DRange(Double min, Double max) {
		this.min = min;
		this.max = max;
	}


	public Double getMin() {
		return min;
	}


	public void setMin(Double min) {
		this.min = min;
	}


	public Double getMax() {
		return max;
	}


	public void setMax(Double max) {
		this.max = max;
	}


	public boolean isWithin(double value) {
		if ((min == null) && (max == null)) {
			return true;
		}
		else if ((min == null) && (max != null)) {
			return value < max;
		}
		else if ((min != null) && (max == null)) {
			return min <= value;
		}
		else {
			return (min < value) && (value <= max);
		}
	}


	@Override
	public int hashCode() {
		int result = min != null ? min.hashCode() : 0;
		result = 31 * result + (max != null ? max.hashCode() : 0);
		return result;
	}

}
